#!/bin/bash

rootwookdir=$(pwd)/../../../trunk/resource/particle
copyTo=$(pwd)/../../../../A2D/trunk/a2d/res/download/particle

echo "copy particle began====================="
function scandirToCopyParticle() { 
    local cur_dir workdir  
    workdir=$1  
    cd ${workdir}  
    if [ ${workdir} = "/" ]  
    then  
        cur_dir=""  
    else  
        cur_dir=$(pwd)  
    fi  

    for dirlist in $(ls ${cur_dir})  
    do  
        if test -d ${dirlist};then  
            cd ${dirlist}  
            scandirToCopyParticle ${cur_dir}/${dirlist} $2  
            cd ..  
        else  
            local pathname=${cur_dir}/${dirlist}  
            if [[ ${pathname:(-${#2})} = $2 ]]   
            then  
                local file=$(basename ${pathname})
                local copyPath=${copyTo}/${file}
                $(cp ${pathname} ${copyPath})
            fi  
        fi  
    done 
}
scandirToCopyParticle ${rootwookdir} ".pux"
cd .. 
echo "copy particle ended====================="

echo "copy mesh began====================="
function scandirToCopyMesh() { 
    local cur_dir workdir  
    workdir=$1  
    cd ${workdir}  
    if [ ${workdir} = "/" ]  
    then  
        cur_dir=""  
    else  
        cur_dir=$(pwd)  
    fi  

    for dirlist in $(ls ${cur_dir})  
    do  
        if test -d ${dirlist};then  
            cd ${dirlist}  
            scandirToCopyMesh ${cur_dir}/${dirlist} $2  
            cd ..  
        else  
            local pathname=${cur_dir}/${dirlist}  
            if [[ ${pathname:(-${#2})} = $2 ]]   
            then  
                local file=$(basename ${pathname})
                local copyPath=${copyTo}/mesh/${file}
                $(cp ${pathname} ${copyPath})
            fi  
        fi  
    done 
}
scandirToCopyMesh ${rootwookdir}/mesh ".c3b"
cd .. 
cd ..
echo "copy mesh ended====================="

echo "copy texture began====================="
function scandirToCopyTexture() { 
    local cur_dir workdir  
    workdir=$1  
    cd ${workdir}  
    if [ ${workdir} = "/" ]  
    then  
        cur_dir=""  
    else  
        cur_dir=$(pwd)  
    fi  

    for dirlist in $(ls ${cur_dir})  
    do  
        if test -d ${dirlist};then  
            cd ${dirlist}  
            scandirToCopyTexture ${cur_dir}/${dirlist} $2  
            cd ..  
        else  
            local pathname=${cur_dir}/${dirlist}  
            if [[ ${pathname:(-${#2})} = $2 ]]   
            then  
                local file=$(basename ${pathname})
                local copyPath=${copyTo}/texture/${file}
                $(cp ${pathname} ${copyPath})
            fi  
        fi  
    done 
}
scandirToCopyTexture ${rootwookdir}/texture ".png"
cd .. 
cd ..
scandirToCopyTexture ${rootwookdir}/texture ".ccz"
cd .. 
cd ..
echo "copy texture ended====================="

echo "copy sound began====================="
function scandirToCopySound() { 
    local cur_dir workdir  
    workdir=$1  
    cd ${workdir}  
    if [ ${workdir} = "/" ]  
    then  
        cur_dir=""  
    else  
        cur_dir=$(pwd)  
    fi  

    for dirlist in $(ls ${cur_dir})  
    do  
        if test -d ${dirlist};then  
            cd ${dirlist}  
            scandirToCopySound ${cur_dir}/${dirlist} $2  
            cd ..  
        else  
            local pathname=${cur_dir}/${dirlist}  
            if [[ ${pathname:(-${#2})} = $2 ]]   
            then  
                local file=$(basename ${pathname})
                local copyPath=${copyTo}/sound/${file}
                $(cp ${pathname} ${copyPath})
            fi  
        fi  
    done 
}
scandirToCopySound ${rootwookdir}/sound ".wav"
cd .. 
cd ..
echo "copy sound ended====================="

echo "copy material began====================="
function scandirToCopyMaterial() { 
    local cur_dir workdir  
    workdir=$1  
    cd ${workdir}  
    if [ ${workdir} = "/" ]  
    then  
        cur_dir=""  
    else  
        cur_dir=$(pwd)  
    fi  

    for dirlist in $(ls ${cur_dir})  
    do  
        if test -d ${dirlist};then  
            cd ${dirlist}  
            scandirToCopyMaterial ${cur_dir}/${dirlist} $2  
            cd ..  
        else  
            local pathname=${cur_dir}/${dirlist}  
            if [[ ${pathname:(-${#2})} = $2 ]]   
            then  
                local file=$(basename ${pathname})
                local copyPath=${copyTo}/material/${file}
                $(cp ${pathname} ${copyPath})
            fi  
        fi  
    done 
}
scandirToCopyMaterial ${rootwookdir}/material ".mat"
cd .. 
cd ..
echo "copy material ended====================="

echo "copy json began====================="
function scandirToCopyJson() { 
    local cur_dir workdir  
    workdir=$1  
    cd ${workdir}  
    if [ ${workdir} = "/" ]  
    then  
        cur_dir=""  
    else  
        cur_dir=$(pwd)  
    fi  

    for dirlist in $(ls ${cur_dir})  
    do  
        if test -d ${dirlist};then  
            cd ${dirlist}  
            scandirToCopyJson ${cur_dir}/${dirlist} $2  
            cd ..  
        else  
            local pathname=${cur_dir}/${dirlist}  
            if [[ ${pathname:(-${#2})} = $2 ]]   
            then  
                local file=$(basename ${pathname})
                local copyPath=${copyTo}/json/${file}
                $(cp ${pathname} ${copyPath})
            fi  
        fi  
    done 
}
scandirToCopyJson ${rootwookdir}/json ".json"
cd .. 
cd ..
echo "copy json ended====================="
